package longrise.phone.com.bjjt_henan.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import longrise.phone.com.bjjt_henan.R;

/**
 * Created by Administrator on 2016/5/19.
 */
public class PromptDialog extends Dialog {

    private ImageView iconIV;

    private TextView infoTV;

    private TextView cancelTV;

    private LinearLayout confirmLayout;

    private TextView confirmTV;

    public PromptDialog(Context context) {
        super(context, R.style.AlertDialogStyle);

        View view = LayoutInflater.from(context).inflate(R.layout.dialog_prompt, null);
        initViews(view);
        setContentView(view);
        //设置大小
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
        lp.width = (int) (d.widthPixels * 0.85);
        dialogWindow.setAttributes(lp);
    }

    private void initViews(View view) {
        iconIV = (ImageView) view.findViewById(R.id.dialog_iv_icon);
        infoTV = (TextView) view.findViewById(R.id.dialog_tv_info);
        cancelTV = (TextView) view.findViewById(R.id.dialog_tv_cancel);
        confirmLayout = (LinearLayout) view.findViewById(R.id.dialog_layout_confirm);
        confirmTV = (TextView) view.findViewById(R.id.dialog_tv_confirm);

        cancelTV.setVisibility(View.GONE);
        confirmLayout.setVisibility(View.GONE);
    }

    public void setIcon(int resId) {
        this.iconIV.setBackgroundResource(resId);
    }

    public void setInfo(CharSequence info) {
        this.infoTV.setText(info);
    }

    public void setInfo(int redId) {
        this.infoTV.setText(redId);
    }

    public void setCancel(String title, View.OnClickListener listener) {
        cancelTV.setVisibility(View.VISIBLE);
        cancelTV.setText(title);
        cancelTV.setOnClickListener(listener);
    }

    public void setConfirm(String title, View.OnClickListener listener) {
        confirmLayout.setVisibility(View.VISIBLE);
        confirmTV.setText(title);
        confirmLayout.setOnClickListener(listener);
    }
}
